<?php

class AllocationHandler{
private $search;
private $allocat;
private $con;

public function setAllocation($allocation)
	{
	$this->allosearch=$allocation;
	}

public function setCat($cat)
	{
	$this->allocat=$cat;
	}

public function setConnect($conn)
	{
	$this->con=$conn;
	}  



public function getPageSearch($startrow,$limit){

$sql=" select class_sched.schedule_id,subject_code.subject,subject_code.grade,class_sched.class_no,subject_code.sub_gr,class_sched.days,class_sched.start,   class_sched.end from
subject_code,class_sched where subject_code.sub_gr=class_sched.sub_gr order by class_sched.schedule_id desc Limit $startrow,$limit";

$result=mysql_query($sql,$this->con)or die(mysql_error());

return $result;

}




public function getSearch($startrow,$limit){

	if($this->allocat=="Grade"){

$sql=" select class_sched.schedule_id,subject_code.subject,subject_code.grade,subject_code.sub_gr,class_sched.class_no,class_sched.days,class_sched.start,   class_sched.end  from
subject_code,class_sched WHERE subject_code.sub_gr=class_sched.sub_gr and subject_code.grade ='$this->allosearch' order by class_sched.schedule_id desc Limit $startrow,$limit";
  } 
  	elseif($this->allocat=="Subject")
	{
 $sql=" select class_sched.schedule_id,subject_code.subject,subject_code.grade,subject_code.sub_gr,class_sched.class_no,class_sched.days,class_sched.start,   class_sched.end from
subject_code,class_sched where subject_code.sub_gr=class_sched.sub_gr and subject_code.subject ='$this->allosearch' order by class_sched.schedule_id desc Limit $startrow,$limit";
}
$result=mysql_query($sql,$this->con)or die(mysql_error());
return $result;
}






public function getDelete($id)
	{
	$sql2="delete  from class_sched where schedule_id='$id' ";
	mysql_query($sql2,$this->con) or die(mysql_error());
	$msgd="sccessfully deleted";
	return $msgd;
	}

public function allocationUpdate($id,$subgr,$days,$start,$end,$class){


$sql="update class_sched set sub_gr='$subgr',days='$days',start='$start',end='$end',class_no='$class' where schedule_id='$id'";

mysql_query($sql,$this->con) or die(mysql_error());

$msg="Successfully Updated";

return $msg;



}



public function getPaginationRow(){

if($this->allocat=="Grade"){
	$sql=" select class_sched.schedule_id,subject_code.subject,subject_code.grade,subject_code.sub_gr,class_sched.class_no,class_sched.days,class_sched.start,   class_sched.end from
subject_code,class_sched where subject_code.sub_gr=class_sched.sub_gr and subject_code.grade ='$this->allosearch'";
}

else
{
 	$sql=" select class_sched.schedule_id,subject_code.subject,subject_code.grade,subject_code.sub_gr,class_sched.class_no,class_sched.days,class_sched.start,   class_sched.end from
subject_code,class_sched where subject_code.sub_gr=class_sched.sub_gr and subject_code.subject ='$this->allosearch'";
}

$result=mysql_query($sql,$this->con)or die(mysql_error());
return $result;
}


}
?>